    var actionState;//提示框状态
    var th;//当前对象
    var cProId;//当前商品Id
    var orderId;//当前订单Id
    
    //滑动选项卡
    window.addEventListener('load', function(){
        var tab = new fz.Scroll('.ui-tab', {
            role: 'tab',
            autoplay: false,
        });

        /* 滑动开始前 */
        tab.on('beforeScrollStart', function(from, to) {
            // from 为当前页，to 为下一页
        })

        /* 滑动结束 */
        tab.on('scrollEnd', function(curPage) {
            // curPage 当前页
        });

    })
    
    //页面加载完毕
    window.onload=function(){
        var aDate = new Date();
       console.log();
       getOrderCount();
    }
    
    
    //展开订单详情
    function hiDiv(t){
        
        var ure=t.id.match(/\d/g).join("");//后缀
        //alert(ure);
        var oi=$('#order_Info'+ure);
        hiAllDiv(oi);
        oi.toggle();
        oi.attr('background-color','red');
        acValuationFrame(null,-1,1);
    }
    
    //隐藏所以订单详情Div
    function hiAllDiv(t){
        var orders=document.getElementsByTagName("div");//遍历页面中所有input元素
        for(var i=0;i<orders.length;i++)
        {
            //过虑并判断
            if(orders[i].id.indexOf('order_Info')!=-1 && orders[i].id.indexOf(t.attr('id'))<0){
                var ure=orders[i].id.match(/\d/g).join("");//后缀
                $('#order_Info'+ure).css('display','none');

            }
        }
    }
    
    //支付
    function payMoney(){
        
        location.href=(handleUrl+"/Payment/loadAddress"+"?OrderId="+th.id.substr(7));
        //console.log(handleUrl+"?OrderId="+$this.id.substr(7));
    }
    
    //取消订单
    function cancelOrder(){
        var OrderId=th.id.substr(th.id.length-10);
        $.post(handleUrl+"/Order/cancelOrder", {isOrderId:OrderId},
            function(response){
                //console.log('test');
                if(response>0){
                    getOrderCount();
                    removeOrder(th);
                    tipMsg('[#'+OrderId+']订单已取消!','success');  
                    
                }else{
                    tipMsg('取消订单失败请联系客服!','warn');
                }
            },'json'
        );
    }
    
    //顶部提示
    function tipMsg($content,$type){
        var el;
        el=$.tips({
            content:$content,
            stayTime:2000,
            type:$type
        })
        
    }
    
    //清理订单
    function removeOrder($Order){
        $Order.parentNode.parentNode.parentNode.remove();
    }
    
    //查看物流
    function lookTrends(){
        $('#div_Wl').show();
        $('#div_Yn').hide();
        $('.ui-dialog').addClass('show').show();
    }
    
    //确认收货
    function conReceive(){
        var OrderId=th.id.substr(th.id.length-10);
        $.post(handleUrl+"/Order/conReceive", {isOrderId:OrderId},
            function(response){
                //console.log('test');
                if(response>0){
                    removeOrder(th);
                    tipMsg('[#'+OrderId+']确认收货，请刷新页面!','success');
                    getOrderCount();
                    //location.reload(true);   
                }else{
                    tipMsg('确认收货失败请联系客服!','warn');
                }
            },'json'
        );  
    }
    
    //再次购买
    function againBuy(){
        
    }
    
    //显示或隐藏商品评价框
    function acValuationFrame($this,$pId,$state){
        cProId=$pId;
        if($this!=null)
            orderId=$($this).parent().parent().parent().parent().parent()[0].id.substr(10);
        //console.log(orderId);
        if($state==2){
            if($('.ui-input-wrap').prop('style').display=="none"){
                $('.ui-input-wrap').show();
            }else
                $('.ui-input-wrap').hide();
            return;
        }
        if($state==0){
            $('.ui-input-wrap').show();
        }else if($state==1){
            $('.ui-input-wrap').hide();
        }    
    }
    
    //商品评价
    function proValuation(){
        //console.log(proId);
        var uId=1;
        var vc=vContent.value;
        var vLevel=i_VLevel.className;//评价级别
        if(vLevel=="iconfont icon-pingjiahaoping"){
            vLevel=1;
        }else if(vLevel=="iconfont icon-pingjiazhongping"){
            vLevel=2; 
        }else if(vLevel=="iconfont icon-pingjiachaping"){
            vLevel=3;
        }
        //console.log(vLevel);
        if(!(vc!="" && vc.length<=60)){//内容合法判断
            tipMsg('内容为空或超过40个字符，请重新输入!','info');
            return ;
        }
        $.post(handleUrl+"/Order/proValuation",{isOrderId:orderId,isContent:vc,isUserId:uId,isProId:cProId,isLevel:vLevel},
            function (response){
                //console.log(response);
                if(response==1){//状态处理反馈
                    tipMsg('您已评价过该商品，请误重复评价!','info');
                }else if(response==4){
                    tipMsg('评价成功!','success');
                }else{
                    tipMsg('评价失败请联系客服!','success');
                }
                vContent.value="";
                acValuationFrame(null,-1,1);
            },'json');
    }
    
    
    //提醒卖家
    function notifyMaster(){
        tipMsg('已提醒卖家，请耐心等待!','info');
    }
    
    //联系卖家
    function callMaster(){
        tipMsg('请用微信联系卖家，或拨打客服电话!','info');
    }
    
    //设置弹出框提示内容与所控制的区域
    function setActionState($content,$state,$this){
        th=$this;
        dialog_content.innerHTML=$content;
        actionState=$state;
        $('#div_Yn').show();
        $('#div_Wl').hide();
        $('.ui-dialog').addClass('show').show();
    }
    
    //弹出框结果处理
    function handleResult(){
        switch (actionState) {
            case 1://取消订单
                cancelOrder();
                break;
            case 2://支付订单
                payMoney();
                break;
            case 3://确认收货
                conReceive();
                break;
            default:
                break;
        }
        $('.ui-dialog').addClass('show').hide();
    }
    
    //获取各订单数
    function getOrderCount(){
        $uId=1;
        $.post(handleUrl+"/Order/getCount",{UserId:$uId},
            function(response){
                setOrderflag(response);
                //console.log(response.length);
            },'json');
    }
    
    //设置订单数量标号
    function setOrderflag(response){
        if(response[0]!=0){//为0则不显示
            menu1_flag.className="ui-badge-muted";
            menu1_flag.innerHTML=response[0];
        }else{
            menu1_flag.className="";
            menu1_flag.innerHTML='';
        }
        if(response[1]!=0){
            menu2_flag.className="ui-badge-muted";
            menu2_flag.innerHTML=response[1];
        }else{
            menu2_flag.className="";
            menu2_flag.innerHTML='';
        }
        
        if(response[2]!=0){
            menu3_flag.className="ui-badge-muted";
            menu3_flag.innerHTML=response[2];
        }else{
            menu3_flag.className="";
            menu3_flag.innerHTML='';
        }
        
        if(response[3]!=0){
            menu4_flag.className="ui-badge-muted";
            menu4_flag.innerHTML=response[3];
        }else{
            menu4_flag.className="";
            menu4_flag.innerHTML='';
        }
        
        
    }
    
    //评级切换   好评->中评->差评->好评
    function gradeSwitch($this){
        var temp=$this.className;
        if(temp=='iconfont icon-pingjiahaoping'){
            $this.className='iconfont icon-pingjiazhongping';
        }else if(temp=='iconfont icon-pingjiazhongping'){
            $this.className='iconfont icon-pingjiachaping';
        }else if(temp=='iconfont icon-pingjiachaping'){
            $this.className='iconfont icon-pingjiahaoping';
        }
    }
    
    //申请售后
    function postService(){
        tipMsg('请联系微信客服!','info');
    }
    
    //跳转到指定商品详情页
    function GotoProDetail(id){
        var Url=handleUrl+'/Index/ProDetail/ProID/'+id;
        location.href=Url;
    }
    
    //遍历并按时间设置所有订单
    function betweenOrder(days){
        //alert(hour);
        var divSet=$("div[id^='order_Info']");
        var time;
        divSet.forEach(function(element) {
            time=new Date($(element).find("input[type='datetime']").val()).getTime()/1000;//获取当前订单10位时间戳
            //console.log(time);
            if(!byTimeShowOrder(time,days)){//按state计算time
                //console.log(element.id.substr(10)+':false');
                $('#div_menu'+element.id.substr(10)).hide();
                $(element).hide();
            }else{
                //console.log(element.id.substr(10)+':true');
                $('#div_menu'+element.id.substr(10)).show();
            }
            
        }, this);
        updateOrderCount();//更新标号
    }
    
    //比较时间差   offset单位:小时
    function byTimeShowOrder(time,days){
        
        if(days==-1){//全部订单
            return true;
        }else if(days == 11){
            days = new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate();//获取当前月天数
        }else if(days == 12){ 
            days = getDays(new Date().getFullYear());
        }
        var cTime=getUnixDay(parseInt(new Date().getTime()/1000));//当前时间天数
        time=getUnixDay(time);//订单天数 
        //console.log('Time:'+time);
        //console.log('cTime'+cTime);
        return (cTime-time  )<=days;
    }
    
    //刷新各个分类下的订单数量
    function updateOrderCount(){
        var isTypes=$('.ui-tab-content').find('li[class^=flagax]');
        var cDisplay;//当前display状态
        var response=[];//存放结果数组
        for (var i = 0; i < 4; i++) {
            var count=0;
            var cDiv=$(isTypes[i]).find('div[id^="div_menu"]');
            
            //console.log(i+'-start');//测试
            
            cDiv.forEach(function(element) {//循环遍历此分类下的订单Div
                
                //console.log(element.id+":"+element.style.display);//测试
                
                if(element.style.display!="none"){//显示状态 
                    count++;//个数加1
                }
            }, this);
            //console.log(i+'-end');//测试
            
            response.push(count);
        }
        //console.log(response);//测试
        setOrderflag(response);
    }
    
    //时间戳取天数
    function getUnixDay(time){
        return parseInt(time/86400);
    }
    
    //判断是否为闰年
    function getDays(year) {  
        if((year % 4 == 0) && (year % 100 != 0 || year % 400 == 0)){
            return year+1;    
        }
        return year;  
    }
    
    
    
    
    